using System.IO;
using System.Reflection;
using GrapeCity.Documents.Excel;
using System;
using System.Data;

namespace GrapeCity.Documents.Excel.Examples.Templates.Pagination.CountPerPagePagination.RepeatWithGroupCollection.RepeatWithGroup2
{
    class Program
    {
        static void Main(string[] args)
        {
			//create a new workbook
			var workbook = new GrapeCity.Documents.Excel.Workbook();
			
			// Load template file from resource
			var templateFile = GetResourceStream("xlsx\\Template_RepeatWithGroup.xlsx");
			workbook.Open(templateFile);
			
			#region Init Data
			DataTable data = new DataTable();
			data.Columns.Add("Company", typeof(string));
			data.Columns.Add("Client", typeof(string));
			data.Columns.Add("SlipNumber", typeof(string));
			data.Columns.Add("Amount", typeof(int));
			
			data.Rows.Add("CompanyA", "ClientA", "Aa00001", 10000);
			data.Rows.Add("CompanyA", "ClientA", "Aa00002", 12000);
			data.Rows.Add("CompanyA", "ClientA", "Aa00003", 12500);
			data.Rows.Add("CompanyA", "ClientA", "Aa00004", 11000);
			data.Rows.Add("CompanyA", "ClientA", "Aa00005", 10000);
			data.Rows.Add("CompanyA", "ClientA", "Aa00006", 11500);
			data.Rows.Add("CompanyA", "ClientB", "Ab00001", 11000);
			data.Rows.Add("CompanyA", "ClientB", "Ab00002", 12300);
			data.Rows.Add("CompanyA", "ClientB", "Ab00003", 12500);
			data.Rows.Add("CompanyA", "ClientB", "Ab00004", 10000);
			data.Rows.Add("CompanyA", "ClientC", "Ac00001", 10000);
			data.Rows.Add("CompanyA", "ClientC", "Ac00002", 10000);
			data.Rows.Add("CompanyA", "ClientD", "Ad00001", 11500);
			data.Rows.Add("CompanyA", "ClientD", "Ad00002", 10500);
			data.Rows.Add("CompanyA", "ClientD", "Ad00003", 15000);
			data.Rows.Add("CompanyA", "ClientD", "Ad00004", 12000);
			data.Rows.Add("CompanyA", "ClientD", "Ad00005", 12500);
			data.Rows.Add("CompanyA", "ClientD", "Ad00007", 10000);
			data.Rows.Add("CompanyA", "ClientE", "Ae00001", 11000);
			data.Rows.Add("CompanyB", "ClientA", "Ba00001", 10000);
			data.Rows.Add("CompanyB", "ClientA", "Ba00002", 11000);
			data.Rows.Add("CompanyB", "ClientB", "Bb00001", 12000);
			data.Rows.Add("CompanyB", "ClientB", "Bb00002", 13000);
			data.Rows.Add("CompanyB", "ClientB", "Bb00003", 15000);
			data.Rows.Add("CompanyB", "ClientB", "Bb00004", 12500);
			data.Rows.Add("CompanyB", "ClientC", "Bc00001", 11500);
			data.Rows.Add("CompanyB", "ClientC", "Bc00002", 10000);
			data.Rows.Add("CompanyC", "ClientA", "Ca00001", 11500);
			data.Rows.Add("CompanyC", "ClientA", "Ca00002", 12500);
			data.Rows.Add("CompanyC", "ClientB", "Cb00001", 10500);
			data.Rows.Add("CompanyC", "ClientB", "Cb00002", 15000);
			data.Rows.Add("CompanyC", "ClientB", "Cc00003", 12000);
			data.Rows.Add("CompanyC", "ClientC", "Cc00001", 13000);
			#endregion
			
			// Set PaginationMode is true.
			workbook.Names.Add("TemplateOptions.PaginationMode", "true");
			
			// Add data source
			workbook.AddDataSource("ds", data);
			// Invoke to process the template
			workbook.ProcessTemplate();
			        
			// Save to an excel file
			workbook.Save("RepeatWithGroup2.xlsx");

        }

		static Stream GetResourceStream(string resourcePath)
        {
            string resource = "RepeatWithGroup2.Resource." + resourcePath.Replace("\\", ".");
            var assembly = typeof(Program).GetTypeInfo().Assembly;
            return assembly.GetManifestResourceStream(resource);
        }

    }
}